package com.example.sources.listener;

import com.example.sources.beans.factory.BeanFactory;
import com.example.sources.util.AnnotationUtil;
import com.example.sources.util.MapBean;

import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import java.util.List;
import java.util.Map;

/**
 * Created by Administrator on 2016/7/18.
 */
public class AnnotationListener implements ServletContextListener{
    private ServletContext servletContext;

    @Override
    public void contextInitialized(ServletContextEvent servletContextEvent) {
        List<MapBean> list = new AnnotationUtil().getRequestMapping();
        BeanFactory beanFactory = new BeanFactory();
        beanFactory.createFactory();
        Map<String,Object> map = beanFactory.getBeansMap();
        this.servletContext = servletContextEvent.getServletContext();
        servletContext.setAttribute("annotationList",list);
        servletContext.setAttribute("beanMap",map);
    }

    @Override
    public void contextDestroyed(ServletContextEvent servletContextEvent) {

    }
}
